﻿@model IEnumerable<StudentPortal.Models.webpages_Roles>

@{
    ViewBag.Title = "Quyền";
	Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row-fluid">
	<div class="span12">

<p>
    @Html.ActionLink("Thêm", "Create", new { }, new {@class="btn blue" })

	<button class="btn green" id="roleUpdate">Cập nhật</button>
</p>
@(Html.Kendo().Grid<StudentPortal.Models.webpages_Roles>()
	.Name("webpages_Roles")
	.Columns(columns =>
	{
			columns.Bound(model => model.RoleName);
				columns.Bound(model => model.DisplayName);
		        columns.Command(command => {command.Custom("Sửa").Click("Edit"); command.Custom("Xóa").Click("Delete");});
	})
	.Groupable()
	.Pageable()
	.Sortable()
	.DataSource(
		dataSource => dataSource.Ajax()
			.Read(read => read.Action("Read", "Roles"))
	)
)

	</div>
</div>
<script type="text/javascript">
	$(document).ready(function () {
		$('#roleUpdate').click(function () {
			$.ajax({
				url: '@Url.Action("Update","Roles")',
				dataType: 'json',
				type: 'post',
				success: function (o) {
					alert(o.Message)
					$('#webpages_Roles').data("kendoGrid").dataSource.read();
				}
			})
		})
	})
	function Edit(e) {
		e.preventDefault();
		var dataItem = this.dataItem($(e.currentTarget).closest('tr'));
		location.href='@Url.Action("Edit","Roles")/'+dataItem.RoleId;
	}
	function Delete(e) {
		e.preventDefault();
		var dataItem = this.dataItem($(e.currentTarget).closest('tr'));
		location.href = '@Url.Action("Delete","Roles")/' + dataItem.RoleId;
	}
</script>
